package com.hitqz.robot.camera.netty;

import cn.hutool.core.util.HexUtil;
import lombok.Data;

@Data
public class PelcodMessage {
    //FF 01 00 53 00 00 54
    public static byte[] header = new byte[]{(byte) 0xFF, (byte) 0x01};

    public byte[] cmd;

    public byte[] data;

    public byte check;

    public PelcodMessage(){

    }

    public PelcodMessage(byte[] cmd, byte[] data) {
        this.cmd = cmd;
        this.data = data;
        this.check = (byte) (header[1] + cmd[0] + cmd[1] + data[0] + data[1]);
    }

    public PelcodMessage(int cmdAndData) {
        byte[] bytes = new byte[4];
        bytes[0] = (byte) ((cmdAndData >> 24) & 0xFF);
        bytes[1] = (byte) ((cmdAndData >> 16) & 0xFF);
        bytes[2] = (byte) ((cmdAndData >> 8) & 0xFF);
        bytes[3] = (byte) (cmdAndData & 0xFF);
        this.cmd = new byte[]{bytes[0], bytes[1]};
        this.data = new byte[]{bytes[2], bytes[3]};
        this.check = (byte) (header[1] + cmd[0] + cmd[1] + data[0] + data[1]);
    }

    public PelcodMessage(byte[] header, byte[] cmd, byte[] data, byte check) {
        PelcodMessage.header = header;
        this.cmd = cmd;
        this.data = data;
        this.check = check;
    }



}
